package com.liutaw.nanjingair.views.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.liutaw.nanjingair.R;
import com.liutaw.nanjingair.models.OtherCityWeather;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by liutao on 16/2/19.
 */
public class OtherCityAdapter extends RecyclerView.Adapter<OtherCityAdapter.ViewHolder>{
    private Context context;
    private List<OtherCityWeather> otherCityWeatherList;

    public OtherCityAdapter(Context context) {
        this.context = context;
        otherCityWeatherList = new ArrayList<>();
        initData();
    }

    private void initData() {
        OtherCityWeather nanjing = new OtherCityWeather();
        nanjing.setLocation("南京");
        nanjing.setDegree("12°~24°");
        otherCityWeatherList.add(nanjing);
        OtherCityWeather yz = new OtherCityWeather();
        yz.setLocation("扬州");
        yz.setDegree("10°~23°");
        otherCityWeatherList.add(yz);
        OtherCityWeather sz = new OtherCityWeather();
        sz.setLocation("苏州");
        sz.setDegree("9°~11°");
        otherCityWeatherList.add(sz);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_othercity_weather_info, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        OtherCityWeather content = otherCityWeatherList.get(position);
        holder.textCityName.setText(content.getLocation());
        holder.textWeatherDegree.setText(content.getDegree());
    }

    @Override
    public int getItemCount() {
        return otherCityWeatherList.size();
    }
    public static class ViewHolder extends RecyclerView.ViewHolder{
        @Bind(R.id.text_city_name)
        TextView textCityName;
        @Bind(R.id.img_weather_state)
        ImageView imgWeatherState;
        @Bind(R.id.text_weather_degree)
        TextView textWeatherDegree;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
